<?php

namespace adminmatrix\admin\lists;

use think\App;

trait ListsPagerTrait
{
    private function initPage() : void
    {
        $this->pageType = $this->request->get('page_type', 1);

        if ($this->pageType == 1) {
            # 分页
            $this->pageNo = $this->request->get('current', 1);
            $this->pageSize = $this->request->get('pageSize', 10);
        } else {
            $this->pageNo = 1;
            $this->pageSize = $this->pageSizeMax;
        }
        
        $this->limitOffset = ($this->pageNo - 1) * $this->pageSize;
        $this->limitLength = $this->pageSize;


    }


    public function autoLimit($query)
    {
        if (isset($this->model) && $this->autoLimit)
        {
            return $query->limit($this->limitOffset , $this->limitLength);
        }

        return $this->query = $query;
    }


}